import time

from xinan_ui.proxy.base_page import PageHandle
from xinan_ui.tools.read_yml_xn import ReadYaml

data_eles = ReadYaml(r'D:\testLi\PythonWork\xinan_ui\config\jdzapp.yml').read_yaml()['PT_login']

class LRLogin(PageHandle):
    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)

    def lr_login(self,account,password):
        #点击登录按钮
        self.click_button(data_eles[0]['点击登录按钮'])
        time.sleep(3)
        #点击融资融券tab
        self.click_button(data_eles[13]['融券融券tab'])
        time.sleep(2)
        #账号输入
        self.input_element(data_eles[1]['账号输入框'],account)
        time.sleep(3)
        #密码输入
        self.input_element(data_eles[2]['密码输入框'], password)
        time.sleep(2)
        #验证码输入
        try:
            self.input_element(data_eles[3]['验证码输入框'], '0000')
            time.sleep(2)
        except:
            print('没有验证码输入')
        #点击登录按钮
        self.click_button(data_eles[4]['登录按钮'])
        time.sleep(2)
        #点击授权通知弹窗
        self.click_button(data_eles[5]['授权通知弹窗'])
        time.sleep(2)
        #点击电话拨打权限弹窗
        self.click_button(data_eles[6]['电话拨打权限弹窗'])
        time.sleep(2)
        # 点击登录按钮
        self.click_button(data_eles[4]['登录按钮'])
        time.sleep(1)
        #点击申请安全证书弹窗
        try:
            self.click_button(data_eles[7]['申请安全证书弹窗'])
            time.sleep(2)
        except:
            print("没有出现申请安全证书弹窗")

        #安全证书确认提交按钮
        try:
            self.click_button(data_eles[8]['安全证书确认提交按钮'])
            time.sleep(2)
        except:
            print("没有出现安全证书确认提交按钮")

        #点击上次登录信息弹窗
        # self.click_button(data_eles[9]['上次登录信息弹窗'])
        # print('上次登录信息弹窗')
        time.sleep(2)
        #点击风险测试提示取消按钮
        try:
            self.click_button(data_eles[10]['风险测试提示取消按钮'])

        except:
            print('没有风险测试提示取消按钮')
        time.sleep(2)
        #点击取消预约打新
        try:
            self.click_button(data_eles[11]['打新提示取消按钮'])
        except:

            print('打新提示取消按钮')
        time.sleep(2)
        #点击上次登录信息弹窗
        self.click_button(data_eles[9]['上次登录信息弹窗'])
        # #风险测评返回上一级按钮
        # self.click_button(data_eles[12]['风险测评返回按钮'])
        time.sleep(3)

        #点击负债到期提示框确定按钮
        try:

            self.click_button(data_eles[14]['负债到期提示框确定按钮'])
            time.sleep(1)
        except:
            print('没出现负债到期提示框')

         #点击安全续期取消按钮
        try:

            self.click_button(data_eles[17]['安全续期取消按钮'])
            time.sleep(1)
        except:
            print('没出现安全续期取消按钮')